using System;
using Microsoft.Xna.Framework;
using ClickerClimber.Managers;

namespace ClickerClimber
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class GameController
    {
        public enum eGameState
        {
            eGameState_PreInit = 0,
            eGameState_Init,
            eGameState_Loop,
            eGameState_End
        };

        private GameTime mTime;
        protected eGameState mGameState = eGameState.eGameState_PreInit;
        private static GameController _instance;
        

        public eGameState GameState
        {
            set
            {
                mGameState = value;
            }
            get
            {
                return mGameState;
            }
        }

        private GameController()
        {
        }

        /// <summary>
        /// Gets the singleton instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static GameController Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new GameController();
                }
                return _instance;
            }
        }

        /// <summary>
        /// Starts up the Singleton
        /// </summary>
        public void StartUp()
        {

        }


        /// <summary>
        /// UpdatePreInit
        /// </summary>
        protected void UpdatePreInit(GameTime gameTime)
        {
            DataManager.Instance.SplashScreenScene.Enable = true;
        }

        /// <summary>
        /// UpdateInit
        /// </summary>
        protected void UpdateInit(GameTime gameTime)
        {
            //TODO hay que inicializar la escena de juego?
            RendererManager.Instance.ChangeScene(DataManager.Instance.GameScene);
            RendererManager.Instance.LoadScene(DataManager.Instance.HUDScene);
            // Play background music
            AudioManager.Instance.playBackgroundMusic(AudioManager.eSound.gameplayMusic);
            mGameState = eGameState.eGameState_Loop;
        }

        /// <summary>
        /// UpdateLoop
        /// </summary>
        protected void UpdateLoop(GameTime gameTime)
        {
            DataManager.Instance.GameScene.Update(gameTime);
            DataManager.Instance.HUDScene.Update(gameTime);
        }

        /// <summary>
        /// UpdateEnd
        /// </summary>
        protected void UpdateEnd(GameTime gameTime)
        {
            //mGameState = eGameState.eGameState_Init;
        }

        /// <summary>
        /// Update
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            mTime = gameTime;
            switch (mGameState)
            {
                case eGameState.eGameState_PreInit:
                    UpdatePreInit(gameTime);
                    break;
                case eGameState.eGameState_Init:
                    UpdateInit(gameTime);
                    break;
                case eGameState.eGameState_Loop:
                    UpdateLoop(gameTime);
                    break;
                case eGameState.eGameState_End:
                    UpdateEnd(gameTime);
                    break;
                default:
                    break;
            }
        }
    }
}